<?php namespace Phpcmf\Controllers\Member;
/**
 * {{duixin.cc}}
 * {{对信社区系统}}
 * 本文件是框架系统文件，二次开发时不可以修改本文件
 **/

class Scorelog extends \Phpcmf\Common
{

    /**
     * 提交支付账单
     */
    public function index() {

        if (IS_POST) {
            $scorelog = \Phpcmf\Service::L('input')->post('scorelog');
            $scorelog['uid'] = (int)$this->member['uid'];
            $scorelog['username'] = (string)$this->member['username'];
            $money = floatval($scorelog['money']);
            if (!$money) {
                $this->_msg(0, dr_lang('金额(%s)不正确', $money));
                exit;
            }
			//dr_debug('scorelog', $scorelog);
			
			$tianshus = \Phpcmf\Service::M()->db->table('1_'.$scorelog['s'].'_form_son')->where('id', $scorelog['quanid'])->get()->getRowArray();
			$tianshu = (int)$tianshus['yxsj'];
			if ($tianshu == 0) {
				$tianshu = 30000;
			} else {
				$tianshu = $tianshu;
			}
			$shijianid = \Phpcmf\Service::M()->db->table('1_'.$scorelog['s'].'_xiazaijifen')->where('cid', $scorelog['id'])->where('uid', $this->uid)->get()->getRowArray();
			
			if ($shijianid) {
			    $this->_msg(0, dr_lang('该账单已支付'));
			} else {
				if ($this->member['score'] < $money) {
					$this->_msg(0, ''.SITE_SCORE.'不够了');
				}
				// 新增记录表
				\Phpcmf\Service::M()->db->table('1_'.$scorelog['s'].'_xiazaijifen')->insert(array(
				    'cid' => $scorelog['id'],
				    'uid' => $this->uid,
					'inputtime' => SYS_TIME,
					'endtime' => SYS_TIME + $tianshu * 3600 * 24,
				));
			}
			
			
			$urls = 'index.php?s='.$scorelog['s'].'&c=son&id='.$scorelog['id'];
			\Phpcmf\Service::M('member')->add_score($this->uid, -$money, $note = '积分下载', $urls, $mark = '', $count = 0, $scorelog['id']);
           
            $url = PAY_URL.'index.php?s='.$scorelog['s'].'&c=son&id='.$scorelog['id'];
            if (IS_API_HTTP || (\Phpcmf\Service::L('input')->get('is_ajax') || IS_API_HTTP || IS_AJAX)) {
                // 回调页面
                $this->_json($rt['code'], $url, '消费成功');
            } else {
                // 跳转到支付页面，必须跳转到统一的主域名中付款
                dr_redirect($url, 'auto');
            }
            exit;
        } else {
            $this->_msg(0, dr_lang('POST请求错误'));
        }
    }
	//阅读积分
	/**
	 * 提交支付账单
	 */
	public function yuedujifen() {
	
	    if (IS_POST) {
	        $scorelog = \Phpcmf\Service::L('input')->post('scorelog');
	        $scorelog['uid'] = (int)$this->member['uid'];
	        $scorelog['username'] = (string)$this->member['username'];
	        $money = floatval($scorelog['money']);
	        if (!$money) {
	            $this->_msg(0, dr_lang('金额(%s)不正确', $money));
	            exit;
	        }
			//dr_debug('scorelog', $scorelog);
			
			$tianshus = \Phpcmf\Service::M()->db->table('1_'.$scorelog['s'].'_form_son')->where('id', $scorelog['quanid'])->get()->getRowArray();
			$tianshu = (int)$tianshus['youxiaoshijian'];
			if ($tianshu == 0) {
				$tianshu = 30000;
			} else {
				$tianshu = $tianshu;
			}
			$shijianid = \Phpcmf\Service::M()->db->table('1_'.$scorelog['s'].'_neirongjifen')->where('cid', $scorelog['id'])->where('uid', $this->uid)->get()->getRowArray();
			
			if ($shijianid) {
			    $this->_msg(0, dr_lang('该账单已支付'));
			} else {
				if ($this->member['score'] < $money) {
					$this->_msg(0, ''.SITE_SCORE.'不够了');
				}
				// 新增记录表
				\Phpcmf\Service::M()->db->table('1_'.$scorelog['s'].'_neirongjifen')->insert(array(
				    'cid' => $scorelog['id'],
				    'uid' => $this->uid,
					'inputtime' => SYS_TIME,
					'endtime' => SYS_TIME + $tianshu * 3600 * 24,
				));
			}
			
			
			$urls = 'index.php?s='.$scorelog['s'].'&c=son&id='.$scorelog['id'];
			\Phpcmf\Service::M('member')->add_score($this->uid, -$money, $note = '积分下载', $urls, $mark = '', $count = 0, $scorelog['id']);
	       
	        $url = PAY_URL.'index.php?s='.$scorelog['s'].'&c=son&id='.$scorelog['id'];
	        if (IS_API_HTTP || (\Phpcmf\Service::L('input')->get('is_ajax') || IS_API_HTTP || IS_AJAX)) {
	            // 回调页面
	            $this->_json($rt['code'], $url, '消费成功');
	        } else {
	            // 跳转到支付页面，必须跳转到统一的主域名中付款
	            dr_redirect($url, 'auto');
	        }
	        exit;
	    } else {
	        $this->_msg(0, dr_lang('POST请求错误'));
	    }
	}

}
